#pragma once
#include"RBTree.h"

namespace Mymap {
	using namespace Tree;

	template<class K, class V>
	class map
	{

		struct keyOfvalue {
			const K& operator()(const pair<const K, V>& data)
			{
				return data.first;
			}
		};
		typedef pair<const K, V> T;

		typedef RBTree<K, T ,keyOfvalue> Tree;
	public:
		typedef typename Tree::Iterator iterator;
		typedef typename Tree::const_Iterator const_iterator;
		typedef typename Tree::reverseIterator reverse_iterator;
		typedef typename Tree::const_reverseIterator const_reverse_iterator;

		pair<iterator,bool> insert(const T& data)
		{
			return 	_tr.Insert(data);
		}
		V& operator[](const K& key)
		{
			return (insert(make_pair(key, V())).first)->second;
		}
		void swap( map& t)
		{
			_tr.swap(t._tr);
		}
		iterator begin()
		{
			return _tr.Begin();
		}

		iterator end()
		{
			return _tr.End();
		}

		const_iterator cbegin()
		{
			return _tr.cBegin();
		}
		const_iterator cend()
		{
			return _tr.cEnd();
		}
		reverse_iterator rbegin()
		{
			return _tr.rBegin();
		}

		reverse_iterator rend()
		{
			return _tr.rEnd();
		}
		
		const_reverse_iterator crbegin()
		{
			return _tr.crBegin();
		}
		const_reverse_iterator crend()
		{
			return _tr.crEnd();
		}
		void clear()
		{
			_tr.Clear();
		}
		bool empty()
		{
			return _tr.Empty();
		}
		int size()
		{
			return _tr.size();
		}
	private:
		Tree _tr;
	};
}